package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import com.zmht.beike.biz.CweekcontentBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.TCweekcontent;

public class CweekcontentBizImpl extends BaseBizImpl implements CweekcontentBiz {

	public boolean deleteCweekContent(Serializable id) {
		try {
			Object obj = this.getCweekcontentDAO().findById(
					TCweekcontent.class, id);
			if (null != obj) {
				this.getCweekcontentDAO().deleteObj(obj);
			}
		} catch (Exception e) {
			return false;
		}
		return true;
	}
	/*
	 * 保存记录
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CweekcontentBiz#saveCweekContent(com.zmht.beike.po.TCweekcontent)
	 */
	public boolean saveCweekContent(TCweekcontent content) {
		try{
			this.getCweekcontentDAO().saveObj(content);
		}catch(Exception e){
			return false;
		}
		return true;
	}
	/*
	 * 获得未保存周主题的内容
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CweekcontentBiz#getCweekContents(java.lang.Integer, int, int)
	 */
	public List getCweekContents(Integer teacherId,Integer week,Integer month, int startIndex, int pageSize) {
		String hql = "from TCweekcontent t where t.teacherId="+teacherId+" and t.cweekId=null and t.month="+month+" and t.week="+week;
		return this.getCweekcontentDAO().findByPage(hql, startIndex, pageSize);
	}
	/*
	 * 获得记录总数
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CweekcontentBiz#getCweekContentTotal(java.lang.Integer)
	 */
	public int getCweekContentTotal(Integer teacherId,Integer week,Integer month) {
		String hql = "from TCweekcontent t where t.teacherId="+teacherId+" and t.cweekId=null and t.month="+month+" and t.week="+week;
		return this.getCweekcontentDAO().findByHQLObj(hql).size();
	}
	public boolean updateCweekContent(TCweekcontent content) {
		try{
			this.getCweekcontentDAO().updateObj(content);
		}catch(Exception e){
			return false;
		}
		return true;
	}
	public TCweekcontent findById(Serializable id) {
		
		return (TCweekcontent)this.getCweekcontentDAO().findById(TCweekcontent.class, id);
	}
	/*
	 * 获得记录
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CweekcontentBiz#getCweekContentsEdit(java.lang.Integer, java.lang.Integer, java.lang.Integer, int, int)
	 */
	public List getCweekContentsEdit(Integer targetId, Integer teacherId,Integer areaId,Integer month,
			Integer week, int startIndex, int pageSize) {
		String hql = "from TCweekcontent t where t.teacherId="+teacherId+" and t.caimId="+targetId+" and t.month="+month+" and t.week="+week;
		if(areaId!=null&&!new Integer(0).equals(areaId)){
			hql += " and t.careaId="+areaId;
		}
		System.out.println(" hql = "+hql);
		return this.getCweekcontentDAO().findByPage(hql, startIndex, pageSize);
	}
	public int getCweekContentsEditTotal(Integer targetId, Integer teacherId,Integer areaId,Integer month,
			Integer week) {
		String hql = "from TCweekcontent t where t.teacherId="+teacherId+" and t.caimId="+targetId+" and t.month="+month+" and t.week="+week;
		if(areaId!=null&&!new Integer(0).equals(areaId)){
			hql += " and t.careaId="+areaId;
		}
		return this.getCweekcontentDAO().findByPageAmount(hql);
	}

}
